import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:ytbusiness/config/style.dart';
import 'package:ytbusiness/config/yt_theme.dart';
import 'package:ytbusiness/page/repair_factory/accessories_query/accessories_info.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';

//配件询价
class RepairsInquiry extends StatefulWidget {
  @override
  _RepairsInquiryState createState() => _RepairsInquiryState();
}

class _RepairsInquiryState extends State<RepairsInquiry>
    with TickerProviderStateMixin {
  TabController _tabController; //tab控制器
  List<String> appBarList = ["配件信息", "车辆信息"];
  List<String> titleList = [
   "车型识别码", "主机厂","车型","销售名称","年款","变速箱","前制动器类型","后制动器类型","发动机型号","进气形式",
    "燃油类型","发动机描述","厂商指导价格","底盘号","车辆类型","轮胎规格"
  ];
  List<String> contentList = [
    "MIH011216A009", "本田（东风本田）","哥瑞","1.5 无级 经典版","2020","无级变速器","通风盘式","鼓式","L15B5","自然吸气",
    "汽油","1.5L L4 131PS 直喷汽油发动机","--","GJ6","轿车","前:185/60 R15 后:185/60 R15"
  ];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = new TabController(length: appBarList.length, vsync: this);

    _tabController.addListener(() {
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: YTStyle.bgColor,
      appBar: AppBar(
        elevation: 0,
        centerTitle: true,
        backgroundColor: Colors.white,
        title: Text(
          "配件询价",
          style: TextStyle(
              color: Color(0xff323232),
              fontSize: setSp(18),
              fontWeight: FontWeight.w600),
          maxLines: 1,
          overflow: TextOverflow.ellipsis,
        ),
        leading: GestureDetector(
          behavior: HitTestBehavior.opaque,
          onTap: () {
            Navigator.pop(context);
          },
          child: Row(
            children: [
              Container(
                  margin: EdgeInsets.only(left: setWidth(15)),
                  width: setWidth(10),
                  height: setWidth(17),
                  child: Image.asset(
                    "assets/images/return.png",
                    fit: BoxFit.cover,
                  )),
            ],
          ),
        ),
        actions: [
          GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: () {
            },
            child: Row(
              children: [
                Container(
                    margin: EdgeInsets.only(right: setWidth(15)),
                    width: setWidth(22),
                    height: setWidth(22),
                    child: Image.asset(
                      "assets/images/repair.png",
                      fit: BoxFit.cover,
                    )),
              ],
            ),
          ),
        ],
      ),
      body:  Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            color: Colors.white,
            child: Row(
              children: [
                TabBar(
                  controller: _tabController,
                  isScrollable: true,
                  labelColor: YTTheme.theme,
                  labelStyle:
                  TextStyle(fontSize: setSp(17), fontWeight: FontWeight.w600),
                  unselectedLabelColor: Color(0xff323232),
                  unselectedLabelStyle:
                  TextStyle(color: Colors.white, fontSize: setSp(17)),
                  indicatorColor: YTTheme.theme,
                  indicatorSize: TabBarIndicatorSize.label,
                  tabs: appBarList
                      .asMap()
                      .map((key, value) {
                    return MapEntry(key, _tabItem(appBarList[key]));
                  })
                      .values
                      .toList(),
                ),
              ],
            ),
          ),
          Expanded(
            child: TabBarView(
              controller: _tabController,
              children: [
                //配件信息
                AccessoriesInfo(),
                //车辆信息
                Container(
                  child: SingleChildScrollView(
                    child:  Container(
                      padding: EdgeInsets.only(top: setWidth(24)),
                      margin: EdgeInsets.only(top: setWidth(15)),
                      color: Colors.white,
                      child: ListView.builder(
                          physics: NeverScrollableScrollPhysics(),
                          shrinkWrap: true,
                          itemCount: titleList.length,
                          itemBuilder: (context,index){
                            return Container(
                              padding: EdgeInsets.only(left: setWidth(15),right: setWidth(15)),
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.start,
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Row(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: [
                                      Container(
                                        child: Text("${titleList[index]}:",style: TextStyle(color: Color(0xff989898),fontSize: setSp(15)),),
                                        width: setWidth(95),
                                      ),
                                      SizedBox(
                                        width: setWidth(17),
                                      ),
                                      Expanded(child: Container(
                                        child: Text("${contentList[index]}",style: TextStyle(color: Color(0xff323232),fontSize: setSp(15)),),
                                      ))
                                    ],
                                  ),
                                  Container(
                                    margin: EdgeInsets.only(top: setWidth(24),bottom: setWidth(24)),
                                    color: Color(0xffF0F0F0),
                                    height: setWidth(0.5),
                                  ),
                                ],
                              ),
                            );

                          }),
                    ),
                  ),
                )
              ],
            ),
          )
        ],
      ),
    );
  }

  Widget _tabItem(String title) {
    return Tab(text: title);
  }
}
